/*     */
package nccloud.web.mmbd.bom0202.action;

/*     */
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.stream.Stream;

import nc.bs.businessevent.BusinessEvent;
import nc.bs.businessevent.EventDispatcher;
/*     */ import nc.itf.bd.bom.bom0202.IBomBillQueryService;
/*     */ import nc.mmbd.utils.factoryparam.MMBDFactoryParameter;
/*     */ import nc.util.mmf.framework.base.MMValueCheck;
/*     */ import nc.vo.bd.bom.bom0202.entity.AggBomVO;
/*     */ import nc.vo.bd.bom.bom0202.entity.BomVO;
/*     */ import nc.vo.bd.bom.bom0202.message.MMBDLangConstBom0202;
/*     */ import nc.vo.ml.NCLangRes4VoTransl;
/*     */ import nc.vo.pub.BusinessException;
/*     */ import nc.vo.pub.lang.UFBoolean;
/*     */ import nc.vo.pub.lang.UFDateTime;
/*     */ import nccloud.framework.core.exception.ExceptionUtils;
/*     */ import nccloud.framework.service.ServiceLocator;
/*     */ import nccloud.framework.web.container.IRequest;
/*     */ import nccloud.framework.web.container.SessionContext;
/*     */ import nccloud.pubitf.baseapp.apprbac.IAppAndOrgPermQueryPubService;
/*     */ import nccloud.web.action.NCCAction;
/*     */ import nccloud.web.mmbd.bom0202.util.BomBatchDisableOperator;
/*     */ import nccloud.web.uapbd.commons.web.ParamUtils;

/*     */
/*     */
/*     */ public class BomDisableAction/*     */ extends NCCAction
/*     */ {
    /*     */ @Override
    public <T> Object execute(IRequest request, T para) throws Exception {
        /*  31 */ ParamUtils param = new ParamUtils(request);
        /*  32 */ List<Map<String, String>> params = (List)param.get("param");
        /*  33 */ Map<String, String> idts = new HashMap<String, String>();
        /*  34 */ for (int i = 0; i < params.size(); i++) {
            /*  35 */ Map<String, String> pa = params.get(i);
            /*  36 */ String id = pa.get("id").toString();
            /*  37 */ String ts = pa.get("ts").toString();
            /*  38 */ idts.put(id, ts);
            /*     */ }
        /*     */
        /*  41 */ IBomBillQueryService query = ServiceLocator.find(IBomBillQueryService.class);
        /*  42 */ AggBomVO[] aggvos = query.queryAggBomByBomID(idts.keySet().toArray(new String[0]));
        /*  43 */ if (MMValueCheck.isEmpty(aggvos)) {
            /*  44 */ ExceptionUtils
                .wrapBusinessException(/*  45 */ NCLangRes4VoTransl.getNCLangRes().getStrByID("bdpub", "0bdpub0057"));
            /*     */ }
        /*  47 */ if (aggvos.length < idts.size()) {
            /*  48 */ ExceptionUtils
                .wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1014369_0", "01014369-0006"));
            /*     */ }
        /*     */
        /*  51 */ for (int i = 0; i < aggvos.length; i++) {
            /*  52 */ String cbomid = ((BomVO)aggvos[i].getParentVO()).getCbomid();
            /*  53 */ UFDateTime oldts = new UFDateTime(idts.get(cbomid));
            /*  54 */ UFDateTime newts = ((BomVO)aggvos[i].getParentVO()).getTs();
            /*  55 */ if (oldts == null || oldts.compareTo(newts) != 0) {
                /*  56 */ ExceptionUtils
                    .wrapBusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("1014369_0", "01014369-0006"));
                /*     */ }
            /*     */ }
        /*     */
        /*     */
        /*  61 */ for (int i = 0; i < aggvos.length; i++) {
            /*  62 */ String str = ((BomVO)aggvos[i].getParentVO()).getTs().toStdString();
            /*     */ }
        /*     */
        /*  65 */ Stream.of(aggvos).forEach(agg ->
        /*  66 */ agg.getParent().setAttributeValue("ts", idts.get(agg.getParent().getPrimaryKey())));
        /*     */
        /*  68 */ if (MMValueCheck.isNotEmpty(aggvos)) {
            /*  69 */ validate(aggvos);
            /*     */
            /*  71 */ return (new BomBatchDisableOperator()).executeBatch(aggvos);
            /*     */ }
        /*     */
        /*     */
        /*     */EventDispatcher.fireEvent(new BusinessEvent("2d6ee96c-12a5-4040-b25a-0c64b5ae2a51", "1068", aggvos));
        /*  76 */ return null;
        /*     */ }

    /*     */
    /*     */ private void validate(AggBomVO[] aggvos) {
        /*  80 */ String lastOrg = (String)aggvos[0].getParentVO().getAttributeValue("pk_org");
        /*  81 */ Stream.of(aggvos).forEach(agg -> {
            /*  82 */ if (!lastOrg.equals(agg.getParentVO().getAttributeValue("pk_org"))) {
                /*  83 */ ExceptionUtils
                    .wrapBusinessException(MMBDLangConstBom0202.getMessageCannotEnableForMultiOrg());
                /*     */ }
            /*     */
        });
        /*  86 */ String pk_group = SessionContext.getInstance().getClientInfo().getPk_group();
        /*  87 */ String userid = SessionContext.getInstance().getClientInfo().getUserid();
        /*  88 */ String appcode = SessionContext.getInstance().getAppcode();
        /*     */
        /*  90 */ Stream.of(aggvos).forEach(agg -> {
            /*  91 */ String[] pk_orgs = null;
            /*     */ try {
                /*  93 */ pk_orgs = ServiceLocator.find(IAppAndOrgPermQueryPubService.class)
                    .queryUserPermOrgPksByApp(userid, appcode, pk_group);
                /*     */ }
            /*  95 */ catch (BusinessException e) {
                /*  96 */ ExceptionUtils.wrapException(e);
                /*     */ }
            /*  98 */ boolean hasperm = false;
            /*  99 */ for (String orgid : pk_orgs) {
                /* 100 */ if (orgid.equals(lastOrg)) {
                    /* 101 */ hasperm = true;
                    /*     */ }
                /*     */ }
            /* 104 */ if (!hasperm) {
                /* 105 */ ExceptionUtils.wrapBusinessException(MMBDLangConstBom0202.getMessageUserNoOrgPermission());
                /*     */ }
            /*     */
            /* 108 */ UFBoolean isEcn = UFBoolean.FALSE;
            /* 109 */ BomVO headvo = (BomVO)agg.getParentVO();
            /* 110 */ isEcn = MMBDFactoryParameter.getMMECN001Value(headvo.getPk_org());
            /* 111 */ if (UFBoolean.TRUE.equals(isEcn))
            /*     */ {
                /* 113 */ ExceptionUtils
                    .wrapBusinessException(MMBDLangConstBom0202.getUnsupportUnEditWhenMMDB001Control());
                /*     */ }
            /*     */
        });
        /*     */ }
    /*     */ }

/* Location:              D:\workspace\yingda\sit-yonbipv3\hotwebs\nccloud\WEB-INF\li\\uiuapbd_nccloud_mm.jar!/nccloud/web/mmbd/bom0202/action/BomDisableAction.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */